package main

import (
	"flag"
	"net/http"
	"net/http/pprof"

	"github.com/prometheus/client_golang/prometheus/promhttp"

	"gitee.com/linxunsdut/cncf01/metrics"

	"gitee.com/linxunsdut/cncf01/controllers"
	"github.com/golang/glog"
)

func main() {
	// 处理日志
	flag.Parse()
	defer glog.Flush()

	metrics.Register()

	serverMux := http.NewServeMux()
	// 业务路由
	serverMux.HandleFunc("/env", controllers.Env)
	serverMux.HandleFunc("/healthz", controllers.Healthz)
	serverMux.HandleFunc("/notice-task", controllers.NoticeTask)

	// 性能分析
	serverMux.HandleFunc("/debug/pprof/", pprof.Index)
	serverMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
	serverMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
	serverMux.HandleFunc("/debug/pprof/trace", pprof.Trace)

	// metrics
	serverMux.HandleFunc("/detail", controllers.Detail)
	serverMux.Handle("/metrics", promhttp.Handler())

	if err := http.ListenAndServe(":80", serverMux); err != nil {
		glog.Fatalf("start http server error: %s", err)
	}
}
